package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/2/7 15:15
 */
@Cmd(code = CrossProtocol.C_VARIETY_GET_REWARD, desc = "请求发奖")
public class GetRewardCrossCmd extends CrossCommand {
    private List<VarietyProto.GetRewardData> getRewardDataList;
    private VarietyProto.GetRewardCrossRespMsg.Builder respMsg;
    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VarietyProto.GetRewardCrossReqMsg msg = VarietyProto.GetRewardCrossReqMsg.parseFrom(packet.getBytes());
        getRewardDataList = msg.getGetRewardDataList();
        playerId = packet.getPlayerId();
        respMsg = VarietyProto.GetRewardCrossRespMsg.newBuilder();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossMatchMgr.getReward(serverId, packet.getPlayerId(), getRewardDataList, respMsg);
    }

    @Override
    public void sendData() {
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_VARIETY_GET_REWARD_FROM_CROSS, respMsg);
        MessageHelper.sendPacket(serverId, playerId, message);
    }
}
